<?php
	$obj=new Post();
	$obj->loadByKey($id);
	
	
	$objMenu=new Menu();
	$objMenu->loadByKey($cid);
	include("FCKeditor/fckeditor.php");
	
	if($_SESSION['goback']=="")
		$_SESSION['goback']="?module=".$module."type=".$obj->NewsTypeID;
?>
<form name="f" action="?module=<?php echo $module?>&action=process&mode=update" method="post" enctype="multipart/form-data">
<div class="ContentTitle">
    <div class="left" style="padding-top:8px"><?php echo $objMenu->MenuName?></div>
    <div class="CMSButton right">
        <a onclick="f.submit()">Save</a>
        <a href="javascript:history.go(-1)">Cancel</a>
    </div>    
    <div class="clear"></div>
</div>
<ul id="ContentTabs" class="shadetabs">
    <li><a id="linkTab1" onclick="ShowHideDiv('Tab',1,3,'link')" class="selected">Hình</a></li>
    <li><a id="linkTab2" onclick="ShowHideDiv('Tab',2,3,'link')">Thông tin sản phẩm</a></li>
    <li><a id="linkTab3" onclick="ShowHideDiv('Tab',3,3,'link')">Thông tin chi tiết</a></li>
	
</ul>       

<div id="Tab1" class="TabContainer ngt_Product">
<!-------------CONTENT OF EACH MODULE ---------------------------->

<table width="100%">
	<tr>
		<td>Hình ảnh: </td>
		<td>
			<table>
				<tr>
					<td>
						<a id="btnAddImage" class="button">Chọn hình</a><br />
                        
                        <img id="preview" src="<?php echo $img->resizePNG($obj->ImagePath,100,100)?>" />
                        <input type="hidden" id="imagepath" name="imagepath" value="<?php echo $obj->ImagePath?>" />
                        <input type="hidden" id="imageid" name="imageid" value="<?php echo $obj->ImageID?>" />
                        <input type="hidden" id="imagethumbnail" name="imagethumbnail" value="<?php echo $img->resizePNG($obj->ImagePath,100,100)?>" />
                        <div id="imageloading"></div>
					</td>
					
				</tr>
                
			</table>
			
		</td>
	</tr>
    <tr>
        <td>
            Danh mục
        </td>
        <td>
            <select name="NewsTypeID">
<?php
	$menu = new Menu();
	$where = " WHERE ModuleID = 'product'";
	$data = $menu->getTable($where);
	foreach($data as $item)
	{
		$sel ='';
		if($cid == $item['MenuID'])
			$sel = 'selected="selected"';
	?>
				<option value="<?php echo $item['MenuID']?>" <?php echo $sel?>><?php echo $item['MenuName']?></option>
	<?php
	}
	?>
            </select>
        </td>
    </tr>
</table>
<!-------------END CONTENT OF EACH MODULE ---------------------------->
</div>
<div id="Tab2" class="TabContainer ngt_Product" style="display:none">
<table width="100%">
		<tr>
		<td>
			Tiêu đề
		</td>
		<td>
			<input type="text" name="Title" value="<?php echo $obj->Title?>"/>
			<input type="hidden" name="PostID" value="<?php echo $obj->PostID?>"/>
            
		</td>
	</tr>
    <tr>
		<td>
			Giá:
		</td>
		<td>
			
			<input type="text" name="Price" value="<?php echo $obj->Price?>"/>
            
		</td>
	</tr>
	<tr>
		<td>
			Tóm tắt:
		</td>
		<td>
			
            <?php
			$oFCKeditor = new FCKeditor('Summary') ;
			$oFCKeditor->BasePath = 'FCKeditor/';
			$oFCKeditor->Width  = '100%' ;
			$oFCKeditor->Height = '600' ;
			$oFCKeditor->Value = $obj->Summary;
			$oFCKeditor->Create() ; 
			?>
		</td>
	</tr>
    <tr>
		<td>
			Trạng thái:
		</td>
		<td>
        	<?php 
			$arr = referToArray($obj->Status);
			?>
			<?php foreach($obj->ListStatus as $key => $val){ ?>
            <input type="checkbox" name="ArrStatus[<?php echo $key?>]" value="<?php echo $key?>" <?php echo in_array($key,$arr)? 'checked="checked"':''?> /> <?php echo $val?><br />
            <?php } ?>
		</td>
	</tr>
	
</table>
</div>
<div id="Tab3" class="TabContainer ngt_Product" style="display:none">
<table width="100%">
	<tr>
		
		<td>
			<?php
			$oFCKeditor = new FCKeditor('Detail') ;
			$oFCKeditor->BasePath = 'FCKeditor/';
			$oFCKeditor->Width  = '100%' ;
			$oFCKeditor->Height = '600' ;
			$oFCKeditor->Value = $obj->Detail;
			$oFCKeditor->Create() ; 
			?>
		</td>
	</tr>
</table>
</div>

<input type="hidden" name="selectfile" id="selectfile" value=""/>
</form>
<script language="javascript" src="scripts/ajaxupload.js"></script>
<script language="javascript" src="scripts/uploadpreview.js"></script>
<script language="javascript" src="scripts/product.js"></script>
<script language="javascript">
color = new Color();
var arr = new Array();
<?php foreach($color->group as $key => $item ) {?>
	arr[<?php echo $key?>] = "<?php echo $item?>";
<?php } ?>
$(document).ready(function() {
	$("#btnSave").hide();
<?php
	
	foreach($color->data as $item)
	{
?>
		$("#ID").val("<?php echo $item['ID']?>")
		$("#ColorName").val("<?php echo $item['ColorName']?>")
		$("#Icon").val("<?php echo $item['Icon']?>")
		$("#IconPath").val("<?php echo $item['IconPath']?>")
		$("#IconThumbnail").val("<?php echo $img->resizePNG($item['IconPath'],100,100)?>")
		$("#ImageColor").val("<?php echo $item['ImageID']?>")
		$("#ImageColorPath").val("<?php echo $item['ImagePath']?>")
		$("#ImageColorThumbnail").val("<?php echo $img->resizePNG($item['ImagePath'],100,100)?>")
		$("#Group").val("<?php echo $item['Group']?>")
		
		color.addColor()
		
<?php
	}
?>
});
function browseIcon(form) 
{
    window.showModalDialog("load.php?path=tblfile/file", form, "dialogWidth:900px; dialogHeight:800px; center:yes");
	if($("#selectfile").val()!="")
	{
		$.getJSON('load.php?path=tblfile/getfile&fileid='+$("#selectfile").val(), 
		function(data) {
			
			$('input#Icon').val(data.files.imageid);
			$('input#IconPath').val(data.files.imagepath);
			$('input#IconThumbnail').val(data.files.imagethumbnail);
			$('#previewIcon').attr("src", data.files.imagethumbnail);
		});
		$("#selectfile").val('');
	}
}

function browseColor(form) 
{
    window.showModalDialog("load.php?path=tblfile/file", form, "dialogWidth:900px; dialogHeight:800px; center:yes");
	if($("#selectfile").val()!="")
	{
		$.getJSON('load.php?path=tblfile/getfile&fileid='+$("#selectfile").val(), 
		function(response) {
			
			$('input#ImageColor').val(response.files.imageid);
			$('input#ImageColorPath').val(response.files.imagepath);
			$('input#ImageColorThumbnail').val(response.files.imagethumbnail);
			$('#previewImageColor').attr("src", response.files.imagethumbnail);
		});
		$("#selectfile").val('');
	}
}
</script>